<template>
	<view>
		<view class="c-box-nobg">
			<c-label title="用户登录"></c-label>
		</view>
		<view class="c-box-nobg">
			<u-form :model="info"  >
				<u-form-item prop="info.username">
					<u-input v-model="info.username" placeholder="请输入用户名"></u-input>
				</u-form-item>
				<u-form-item prop="info.password">
					<u-input v-model="info.password" placeholder="请输入密码"></u-input>
				</u-form-item>
			</u-form>
			<view class="mt32">
				<u-button type="primary" text="登录" @click="login"></u-button>
			</view>
		</view>

	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
import { loginApi } from '../../api/member';
	const info = ref({
		username: '',
		password: ''
	})
	const login = async () => {
		if(!info.value.username||!info.value.password){
			uni.showToast({
				title:'请输入用户名或密码'
			})
			return
		}
		const res = await  loginApi(info.value)
		if(res.code==200){
			uni.setStorageSync('token',res.token)
			uni.showToast({
				title:"登录成功"
			})
			setTimeout(()=>{
				uni.navigateBack()
			},500)
		}
		else{
			uni.showToast({
				title:res.msg,
				icon:"none"
			})
		}
		
	}
	
</script>

<style>

</style>